﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using System.Text.RegularExpressions;
using MSScriptControl;

namespace TaobaoLibrary
{
    public class ConfigParser
    {
        public static dynamic ParserConfigToObject(string input)
        {
            int startIndex = input.IndexOf("g_config");
            if (startIndex == -1)
                //TODO: 使用自定义异常
                throw new Exception();
            int endIndex = input.IndexOf(";\r\n", startIndex) + 1;
            string strConfig = input.Substring(startIndex, endIndex - startIndex);
            ScriptControl sc = new ScriptControl();
            sc.Language = "javascript";
            sc.AddCode(strConfig);
            dynamic result = sc.Eval("g_config");
            return result;
        }
    }
}
